<?php
/**
 * 数据统计
 * @author hushuai
 */

class TotalAction extends CommonAction {
	
	public function _initialize() {
		parent::_initialize();
		parent::_initmenu();	
	}
	
	/**
	 * 数据统计首頁
	 */
	public function index(){
		
		$this->display();
	}

	/**
	 * 分享统计
	 */ 
	public function chart_share(){
		if(IS_AJAX){
			
			$userid = $this->_get("userid","intval",0);
			if($userid){
				$maps['userid'] = $userid;
			}
			
			$type   = $this->_param("type","trim","day");
			$func   = $this->_param("func","trim","timeamount");
			
			$maps['type'] = $type;
			$maps['func'] = $func;
			if($func == "timeamount"){
				$maps['num'] = $this->_param("num","intval",5);
			}else{
				$maps['start'] = $this->_param("start","trim","");
				$maps['end']   = $this->_param("end","trim","");
			}
			$json = sendRest("Total/share_chart",$maps);
			$this->ajaxReturn($json['data']);
		}else{
			$this->display();
		}
		
	}
	
	/**
	 * 会员卡统计
	 */
	 public function chart_vip(){
	 	if(IS_AJAX){
	 		$type       = $this->_param("type","trim","day");
	 		$func       = $this->_param("func","trim","timeamount");
	 		$maps['id'] = $this->_param("id");
	 		$maps['type'] = $type;
	 		$maps['func'] = $func;
	 		if($func == "timeamount"){
	 			$maps['num'] = $this->_param("num","intval",5);
	 			$json = sendRest("Total/vip_chart",$maps);
	 		}else{
	 			$maps['start'] = $this->_param("start","trim","");
	 			$maps['end']   = $this->_param("end","trim","");
	 			$json = sendRest("Total/vip_chart",$maps);
	 		}
	 		$this->ajaxReturn($json['data']);
	 	}else{
	 		$json = sendRest("Vip/listall");
	 		$this->assign("list",$json['data']);
	 		$this->display();
	 	}
	}
	
	/**
	 * 优惠卷统计
	 */
	public function chart_yhj(){
		if(IS_AJAX){
			$types      = $this->_param("types","trim","lq");
			$type       = $this->_param("type","trim","day");
			$func       = $this->_param("func","trim","timeamount");
			$maps['id'] = $this->_param("id");
			$maps['type'] = $type;
			$maps['func'] = $func;
			if($types=="lq"){
				$maps['flag']      = "chart_yhj";
				if($func == "timeamount"){
					$maps['num']   = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}else{
				$maps['flag']      = "chartUse_yhj";
				if($func == "timeamount"){
					$maps['num']   = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}
			$json = sendRest("Total/chart_yhj",$maps);
			$this->ajaxReturn($json['data']);
		}else{
			
			$json = sendRest("Coupon/listall");
			$this->assign("list",$json['data']);
			$this->display();
		}
	}
	/**
	 * 订单统计
	 */
	public function chart_order(){
		if(IS_AJAX){
			$types           	   = $this->_param("types","trim","dd");
			$type             	   = $this->_param("type","trim","day");
			$func                  = $this->_param("func","trim","timeamount");
			$maps['type']          = $type;
			$maps['func']          = $func;
			if($types=="dd"){	
				$maps['flag']      = "totalfee";
				if($func == "timeamount"){
					$maps['num']   = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}elseif($types=="sj"){
				$maps['flag']      = "realtotalfee";
				if($func == "timeamount"){
					$maps['num']   = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}else{
				$maps['flag']      = "cardfee";
				if($func == "timeamount"){
					$maps['num']   = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}
			$json = sendRest("Total/chart_order",$maps);
			$this->ajaxReturn($json['data']);
		}else{
			$this->display();
		}
		
	}
	
	/**
	 * 会员统计
	 */
	public function chart_member(){
		if(IS_AJAX){
			$type       = $this->_param("type","trim","day");
			$types      = $this->_param("types","trim","xb");
			$func       = $this->_param("func","trim","timeamount");
			$maps['type'] = $type;
			$maps['func'] = $func;
			if($types=="xb"){
				$maps['flag']  = "member_sex";
				if($func == "timeamount"){
					$maps['num'] = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}else{
				$maps['flag']  = "member_regNum";
				if($func == "timeamount"){
					$maps['num'] = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}
			$json = sendRest("Total/chart_member",$maps);
			$this->ajaxReturn($json['data']);
		}else{
			$this->display();
		}
	}
	/**
	 * 短信统计
	 */
	public function chart_sms(){
		if(IS_AJAX){
			$type       = $this->_param("type","trim","day");
			$types      = $this->_param("types","trim","	");
			$func       = $this->_param("func","trim","timeamount");
			$maps['type'] = $type;
			$maps['func'] = $func;
			if($types=="sms_num"){
				$maps['flag']  = "sms_num";
				if($func == "timeamount"){
					$maps['num'] = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}else{
				$maps['flag']  = "sms_status";
				if($func == "timeamount"){
					$maps['num'] = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}
			$json = sendRest("Total/chart_sms",$maps);
			$this->ajaxReturn($json['data']);
		}else{
			$this->display();
		}
	}
	
	public function chart_email(){
		if(IS_AJAX){
			$type       = $this->_param("type","trim","day");
			$types      = $this->_param("types","trim","email_num");
			$func       = $this->_param("func","trim","timeamount");
			$maps['type'] = $type;
			$maps['func'] = $func;
			if($types=="email_num"){
				$maps['flag']  = "email_num";
				if($func == "timeamount"){
					$maps['num'] = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}else{
				$maps['flag']  = "email_status";
				if($func == "timeamount"){
					$maps['num'] = $this->_param("num","intval",5);
				}else{
					$maps['start'] = $this->_param("start","trim","");
					$maps['end']   = $this->_param("end","trim","");
				}
			}
			$json = sendRest("Total/chart_email",$maps);
			$this->ajaxReturn($json['data']);
		}else{
			$this->display();
		}
	}

}

?>